package indi.jp.project.core.service.impl;

import indi.jp.project.core.dao.AttachmentDAO;
import indi.jp.project.core.entity.po.AttachmentPO;
import indi.jp.project.core.service.AttachmentService;
import indi.jp.project.core.util.SerialUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 附件Service实现
 *
 * @author jiangping
 * @date 2022/5/14
 */
@Service
public class AttachmentServiceImpl implements AttachmentService {

    @Resource
    private AttachmentDAO attachmentDAO;

    @Resource
    private SerialUtil serialUtil;

    @Override
    public void deleteById(String id) throws Exception {
        attachmentDAO.deleteById(id);
    }

    @Override
    public void delete(String sId) throws Exception {
        attachmentDAO.delete(sId, null);
    }

    @Override
    public void delete(String sId, int category) throws Exception {
        attachmentDAO.delete(sId, category);
    }

    @Override
    public void save(AttachmentPO attachmentPO, String sId) throws Exception {
        attachmentPO.setId(String.valueOf(serialUtil.nextId()));
        attachmentPO.setsId(sId);
        attachmentDAO.insert(attachmentPO);
    }

    @Override
    public void save(List<AttachmentPO> list, String sId) throws Exception {
        for(AttachmentPO po : list){
            po.setId(String.valueOf(serialUtil.nextId()));
            po.setsId(sId);
        }
        attachmentDAO.batchInsert(list);
    }

    @Override
    public List<AttachmentPO> queryAttachments(String sId, Integer category) throws Exception {
        return attachmentDAO.queryList(sId, category);
    }
}
